import { reactive, ref } from 'vue'
import { addRow } from './table.js'
export let disabled = ref(false)
export let dialogVisible = ref(false)
export let dialogForm = ref(null)
export let dialogFormData = reactive({
  name: '',
  date: '',
  address: '',
})
export let dialogFormItems = reactive([
  {
    type: 'input',
    label: '姓名',
    value: 'name',
    disabled: disabled,
  },
  {
    type: 'date',
    label: '日期',
    value: 'date',
    disabled: disabled,
  },
  {
    type: 'input',
    label: '地址',
    value: 'address',
    disabled: disabled,
  },
])
export let dialogRules = reactive({})
export function dialogOk() {
  dialogForm.value
    .validate()
    .then(() => {
      addRow(dialogFormData)
    })
    .catch(() => {
      console.log('不通过')
    })
  dialogCancel()
}
export function dialogCancel() {
  dialogVisible.value = false
  dialogForm.value.resetFields()
}
export function setDialogForm(data) {
  Object.assign(dialogFormData, data)
}
